#!/bin/sh
NTPSRVSITE="tock.stdtime.gov.tw watch.stdtime.gov.tw"
if [ ! -s /tmp/.ntp.log ]; then
  for i in $NTPSRVSITE
  do
        if ping -4 -c 1 -w 1 $i -I $IFACE > /dev/null; then
                /usr/netplug/bin/ntpclient -s -h $i -i 3 > /tmp/.ntp.log &
                wait $!
                if [ -s /tmp/.ntp.log ]; then
                        echo "Synced with $i"   > /dev/tty0
                        date > /dev/tty0
                        hwclock -w      # Refresh RTC time
                        exit 0
                fi
        fi
  done
  echo "Synchronize failure!!"   /dev/tty0
  exit 1
fi
exit 0
